import { message } from 'antd';
export default {
  namespace: 'hdst',
  state: {
    camZmcParams: [], // 拍照控制器参数
    cbjZmcParams: [], // 裁切机控制器参数
    bigCutterZmcParams: [], // 大铡刀控制器参数
    smallCutterZmcParams: [], // 小铡刀控制器参数
    lineCamCheckThres: [], // 上料线阵相机计算用阈值参数
    bigCutterCamCheckThres: [], // 铡刀面阵相机计算用阈值参数
    smallCutterCamCheckThres: [], // 铡刀面阵相机计算用阈值参数
    configParams: [], // 设备设置参数,包括相机还有其他的一些参数
    AdjustLightParams: [],
    cameraIP: [], // 相机IP集
  },
  effects: {
    *handleSettingsUpdate({ payload }, { call, put }) {
      yield put({
        type: 'getCamZmcParams',
      });
      yield put({
        type: 'getCbjZmcParams',
      });
      yield put({
        type: 'getbigCutterZmcParams',
      });
      yield put({
        type: 'getsmallCutterZmcParams',
      });
      yield put({
        type: 'getLineCamCheckThres',
      });
      yield put({
        type: 'getCutterCamCheckThresBig',
      });
      yield put({
        type: 'getCutterCamCheckThresSmall',
      });
      yield put({
        type: 'getCameraIP',
      });
    },

    *getCamZmcParams({ payload }, { call, put }) {
      const response = yield call(
        window.eel.run_py,
        'camZmc',
        'web_request_get_cam_zmc_params',
        []
      );
      yield put({
        type: 'updateCamZmcParams',
        payload: response,
      });
    },
    *saveCamZmcParams({ payload }, { call, put }) {
      const response = yield call(window.eel.run_py, 'camZmc', 'web_request_save_cam_zmc_params', [
        payload,
      ]);
      if (response === 'ok') {
        message.success('保存成功!');
      } else {
        message.error('保存失败,', response);
      }
      yield put({
        type: 'getCamZmcParams',
      });
    },
    *getCbjZmcParams({ payload }, { call, put }) {
      const response = yield call(
        window.eel.run_py,
        'cbjZmc',
        'web_request_get_cbj_zmc_params',
        []
      );
      yield put({
        type: 'updateCbjZmcParams',
        payload: response,
      });
    },
    *saveCbjZmcParams({ payload }, { call, put }) {
      const response = yield call(window.eel.run_py, 'cbjZmc', 'web_request_save_cbj_zmc_params', [
        payload,
      ]);
      if (response === 'ok') {
        message.success('保存成功!');
      } else {
        message.error('保存失败,', response);
      }
      yield put({
        type: 'getCbjZmcParams',
      });
    },
    *getbigCutterZmcParams({ payload }, { call, put }) {
      const response = yield call(
        window.eel.run_py,
        'bigCutterZmc',
        'web_request_get_cutter_zmc_params',
        []
      );
      yield put({
        type: 'updatebigCutterZmcParams',
        payload: response,
      });
    },
    *savebigCutterZmcParams({ payload }, { call, put }) {
      const response = yield call(
        window.eel.run_py,
        'bigCutterZmc',
        'web_request_save_cutter_zmc_params',
        [payload]
      );
      if (response === 'ok') {
        message.success('保存成功!');
      } else {
        message.error('保存失败,', response);
      }
      yield put({
        type: 'getbigCutterZmcParams',
      });
    },
    *getsmallCutterZmcParams({ payload }, { call, put }) {
      const response = yield call(
        window.eel.run_py,
        'smallCutterZmc',
        'web_request_get_cutter_zmc_params',
        []
      );
      yield put({
        type: 'updatesmallCutterZmcParams',
        payload: response,
      });
    },
    *savesmallCutterZmcParams({ payload }, { call, put }) {
      const response = yield call(
        window.eel.run_py,
        'smallCutterZmc',
        'web_request_save_cutter_zmc_params',
        [payload]
      );
      if (response === 'ok') {
        message.success('保存成功!');
      } else {
        message.error('保存失败,', response);
      }
      yield put({
        type: 'getsmallCutterZmcParams',
      });
    },
    *getLineCamCheckThres({ payload }, { call, put }) {
      const response = yield call(
        window.eel.run_py,
        'ph',
        'web_request_get_line_cam_check_thres',
        []
      );
      yield put({
        type: 'updateLineCamCheckThres',
        payload: response,
      });
    },
    *saveLineCamCheckThres({ payload }, { call, put }) {
      const response = yield call(
        window.eel.run_py,
        'ph',
        'web_request_save_line_cam_check_thres',
        [payload]
      );
      if (response === 'ok') {
        message.success('保存成功!');
      } else {
        message.error('保存失败,' + response, 5);
      }
      yield put({
        type: 'getLineCamCheckThres',
      });
    },
    *getCutterCamCheckThresBig({ payload }, { call, put }) {
      const response = yield call(
        window.eel.run_py,
        'ph',
        'web_request_get_cutter_cam_check_thres_big',
        []
      );
      yield put({
        type: 'updateCutterCamCheckThresBig',
        payload: response,
      });
    },
    *getCutterCamCheckThresSmall({ payload }, { call, put }) {
      const response = yield call(
        window.eel.run_py,
        'ph',
        'web_request_get_cutter_cam_check_thres_small',
        []
      );
      yield put({
        type: 'updateCutterCamCheckThresSmall',
        payload: response,
      });
    },
    *saveCutterCamCheckThresBig({ payload }, { call, put }) {
      const response = yield call(
        window.eel.run_py,
        'ph',
        'web_request_save_cutter_cam_check_thres_big',
        [payload]
      );
      if (response === 'ok') {
        message.success('保存成功!');
      } else {
        message.error('保存失败,' + response, 5);
      }
      yield put({
        type: 'getCutterCamCheckThresBig',
      });
    },
    *saveCutterCamCheckThresSmall({ payload }, { call, put }) {
      const response = yield call(
        window.eel.run_py,
        'ph',
        'web_request_save_cutter_cam_check_thres_small',
        [payload]
      );
      if (response === 'ok') {
        message.success('保存成功!');
      } else {
        message.error('保存失败,' + response, 5);
      }
      yield put({
        type: 'getCutterCamCheckThresSmall',
      });
    },
    *getAdjustLightCamParams({ payload }, { call, put }) {
      const response = yield call(
        window.eel.run_py,
        'camZmc',
        'web_request_get_adjust_light_cam_params',
        []
      );
      yield put({
        type: 'updateAdjustLightCamParams',
        payload: response,
      });
    },
    *saveCamZmcMotionParams({ payload }, { call, put }) {
      const response = yield call(
        window.eel.run_py,
        'camZmc',
        'web_request_save_adjust_light_cam_params',
        [payload]
      );
      if (response === 'ok') {
        message.success('保存成功!');
      } else {
        message.error('保存失败,', response);
      }
      yield put({
        type: 'getAdjustLightCamParams',
      });
    },
    *getCameraIP({ payload }, { call, put }) {
      const response = yield call(window.eel.run_py, 'ph', 'web_request_get_camera_ip', []);
      yield put({
        type: 'updateCameraIP',
        payload: response,
      });
    },
    *saveCameraIP({ payload }, { call, put }) {
      const response = yield call(
        window.eel.run_py,
        'db',
        'web_request_save_cam_IP_connect_info_data',
        [payload]
      );
      if (response[0] === 'ok') {
        message.success('保存成功!');
      } else {
        message.error('保存失败,', response);
      }
      yield put({
        type: 'getCameraIP',
      });
    },
  },
  reducers: {
    updateCamZmcParams(state, action) {
      return {
        ...state,
        camZmcParams: action.payload,
      };
    },
    updateCbjZmcParams(state, action) {
      return {
        ...state,
        cbjZmcParams: action.payload,
      };
    },
    updatebigCutterZmcParams(state, action) {
      return {
        ...state,
        bigCutterZmcParams: action.payload,
      };
    },
    updatesmallCutterZmcParams(state, action) {
      return {
        ...state,
        smallCutterZmcParams: action.payload,
      };
    },
    updateLineCamCheckThres(state, action) {
      return {
        ...state,
        lineCamCheckThres: action.payload,
      };
    },
    updateCutterCamCheckThresBig(state, action) {
      return {
        ...state,
        bigCutterCamCheckThres: action.payload,
      };
    },
    updateCutterCamCheckThresSmall(state, action) {
      return {
        ...state,
        smallCutterCamCheckThres: action.payload,
      };
    },
    updateAdjustLightCamParams(state, action) {
      return {
        ...state,
        AdjustLightParams: action.payload,
      };
    },
    updateCameraIP(state, action) {
      return {
        ...state,
        cameraIP: action.payload,
      };
    },
  },
};
